package com.yxkj.syh.app.huarong.adps;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import com.syh.app.basic.base.BaseAdp;
import com.yxkj.syh.app.huarong.BR;
import com.yxkj.syh.app.huarong.R;
import com.yxkj.syh.app.huarong.bean.Linkman;
import com.yxkj.syh.app.huarong.bean.Payment;

/**
 * 创建者：SYH
 * 时间：2020/5/25 16:16
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class LinkListAdp extends BaseAdp<Linkman> {
    private OnViewClick mOnViewClick;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_link_list, parent, false);
        View view = binding.getRoot();
        view.setTag(binding);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (mOnViewClick != null) {
            holder.itemView.setOnClickListener(v -> {
                mOnViewClick.onItem(mData.get(position));
            });
            ((ViewHolder)holder).flCall.setOnClickListener(v -> {
                mOnViewClick.onCall(mData.get(position).getMobile());
            });
        }

        Linkman linkman = mData.get(position);
        if (linkman.getSilence()>=25){
            ((ViewHolder)holder).tvSilence.setTextColor(Color.parseColor("#FF4606"));
            ((ViewHolder)holder).tvSilence.setBackgroundResource(R.drawable.shape_long_time_no_call2);
        }else if (linkman.getSilence()>=15){
            ((ViewHolder)holder).tvSilence.setTextColor(Color.parseColor("#FFAB00"));
            ((ViewHolder)holder).tvSilence.setBackgroundResource(R.drawable.shape_long_time_no_call1);
        }

        ViewDataBinding binding = (ViewDataBinding) holder.itemView.getTag();
        binding.setVariable(BR.linkman, mData.get(position));
        binding.executePendingBindings();
    }

    public void setOnViewClick(OnViewClick onViewClick) {
        this.mOnViewClick = onViewClick;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        FrameLayout flCall;
        TextView tvSilence;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            flCall = itemView.findViewById(R.id.flCall);
            tvSilence = itemView.findViewById(R.id.tvSilence);
        }
    }

    public interface OnViewClick {
        void onItem(Linkman linkman);

        void onCall(String mobile);
    }

}
